package tcpServerTest

import (
	"fmt"
	"net"
)

func Server() {
	lis, err := net.Listen("tcp", ":8089")
	if err != nil {
		fmt.Println(err)
		return
	}
	defer lis.Close()
	i := 0
	for {
		conn, err := lis.Accept()
		if err != nil {
			fmt.Println("建立连接错误:", err)
			continue
		}
		i++
		fmt.Println("--------------")
		fmt.Println("i的值", i)
		fmt.Println(conn)
		fmt.Println("--------------")
		fmt.Println(conn.RemoteAddr(), conn.LocalAddr())
		go handle(conn)
	}
}

func handle(sconn net.Conn) {
	defer sconn.Close()
	buf := make([]byte, 1024)
	x, _ := sconn.Read(buf)
	fmt.Println(string(buf[:x]))
}
